package cn.cena.pay.controller;

import cn.cena.basic.Exception.MyException;
import cn.cena.basic.util.AjaxResult;
import cn.cena.pay.dto.AlipayNotifyDto;
import cn.cena.pay.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    /**
     * 支付申请
     * @return
     */
    @PostMapping("/applyPay/{orderSn}")
    public AjaxResult applyPay(@PathVariable("orderSn") String orderSn){

        try {
            String htmlResult = payService.applyPay(orderSn);
            System.out.println(htmlResult);
            return AjaxResult.result().setResultObj(htmlResult);
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.result().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.result().setMsg("系统异常");
        }

    }

    @PostMapping("/notify")
    public String alipayNotify(AlipayNotifyDto dto){

        return payService.alipayNotify(dto);
    }
}
